<template>
<div>
  <div v-if="choiceInfo.grade === '8'">
    <doorplate-level-info @reloadData="reloadData" :choiceInfo="choiceInfo" :floorData="floorData"></doorplate-level-info>
  </div>
  <div v-else>
    <Button type="success" v-if="companyInfo.grade === '5'" @click="createGrid" style="margin-bottom: 10px">添加</Button>
    <Table border :columns="columns" :data="data">
      <template slot-scope="{ row, index }" slot="action">
        <Button @click="createQHCode(row)" style="margin-right: 5px"
                v-show="companyInfo.grade === '5' && (row.grade === '5.5' || row.grade === '6')"
                type="success" size="small">{{row.qh_code === undefined ? '添加编码' : '修改编码'}}</Button>
        <Button type="primary" size="small" style="margin-right: 5px" @click="updateGrid(row)">修改</Button>
        <Button type="error" v-if="parseFloat(row.grade) > 5 && companyInfo.grade === '5'" size="small" @click="deleteGrid(row)">删除</Button>
      </template>
    </Table>
  </div>
<!--  小区-->
  <Modal
      v-model="createGridLevel.Modal"
      :title="createGridLevel.title"
      @on-ok="createGridConfirm('create')">
    <div style="width: 80%">
      <Form :model="createGridLevel.info" :label-width="150">
        <FormItem label="小区名称">
          <Input style="width: 300px" v-model="createGridLevel.info.name"></Input>
        </FormItem>
        <FormItem label="小区详细地址">
          <Input style="width: 300px" v-model="createGridLevel.info.address" type="textarea"></Input>
        </FormItem>
        <FormItem v-if="createGridLevel.info.address" label="小区面积">
          <Input style="width: 300px" v-model="createGridLevel.info.measure" disabled></Input>
        </FormItem>
        <FormItem label="小区坐标">
          <Row>
            <Col span="20">
              <Input style="width: 180px" disabled v-if="createGridLevel.info.mapType === 'HT'" v-model="createGridLevel.info.csc_mapjson_ht"></Input>
              <Input style="width: 180px" disabled v-else v-model="createGridLevel.info.csc_mapjson"></Input>
            </Col>
            <Col span="4">
              <Button style="margin-left: 5px" @click="clickResidential">选择</Button>
            </Col>
          </Row>
        </FormItem>
        <FormItem label="小区类型">
          <Select style="width: 300px" v-model="createGridLevel.info.type" filterable>
            <Option value="1">专业化</Option>
            <Option value="2">保障型</Option>
            <Option value="3">产权自管</Option>
            <Option value="4">业主自治</Option>
            <Option value="5">散体楼</Option>
          </Select>
        </FormItem>
        <FormItem label="市直单位包保">
          <Input style="width: 300px" v-model="createGridLevel.info.szdwbb" type="text" placeholder="市直单位包保"></Input>
        </FormItem>
        <FormItem label="市直单位所属党支部包保">
          <Input style="width: 300px" v-model="createGridLevel.info.szdzbbb" type="textarea" placeholder="市直单位所属党支部包保"></Input>
        </FormItem>
      </Form>
    </div>
  </Modal>
  <Modal
      v-model="updateGridLevel.Modal"
      :title="updateGridLevel.title"
      @on-ok="createGridConfirm('update')">
    <div style="width: 80%">
      <Form :model="updateGridLevel.info" :label-width="150">
      <FormItem label="小区名称">
        <Input style="width: 300px" v-model="updateGridLevel.info.name"></Input>
      </FormItem>
      <FormItem v-if="updateGridLevel.info.address" label="小区详细地址">
        <Input style="width: 300px" v-model="updateGridLevel.info.address" type="textarea"></Input>
      </FormItem>
      <FormItem v-if="updateGridLevel.info.address" label="小区面积">
        <Input style="width: 300px" v-model="updateGridLevel.info.measure" disabled></Input>
      </FormItem>
      <FormItem label="小区坐标">
        <Row>
          <Col span="20">
            <Input style="width: 180px" disabled v-if="mapType === 'HT'" v-model="updateGridLevel.info.csc_mapjson_ht"></Input>
              <Input style="width: 180px" disabled v-else v-model="updateGridLevel.info.csc_mapjson"></Input>
          </Col>
          <Col span="4">
            <Button style="margin-left: 5px" @click="clickResidentialForUpdate">选择</Button>
          </Col>
        </Row>
      </FormItem>
      <FormItem label="小区类型">
        <Select style="width: 300px" v-model="updateGridLevel.info.type" filterable>
          <Option value="1">专业化</Option>
          <Option value="2">保障型</Option>
          <Option value="3">产权自管</Option>
          <Option value="4">业主自治</Option>
          <Option value="5">散体楼</Option>
        </Select>
      </FormItem>
      <FormItem label="市直单位包保">
        <Input style="width: 300px" v-model="updateGridLevel.info.szdwbb" type="text" placeholder="市直单位包保"></Input>
      </FormItem>
      <FormItem label="市直单位所属党支部包保">
        <Input style="width: 300px" v-model="updateGridLevel.info.szdzbbb" type="textarea" placeholder="市直单位所属党支部包保"></Input>
      </FormItem>
    </Form>
    </div>
  </Modal>
  <map-polygon-for-residential ref="mapPolygonResidential" @returnMapInfoForResidential="returnMapInfoForResidential"></map-polygon-for-residential>
<!--  网格-->
  <Modal
      v-model="Garden.Modal"
      :title="Garden.title">
    <div style="width: 80%">
      <Form :model="Garden.info" :label-width="100">
        <FormItem label="网格名称">
          <Input style="width: 300px" v-model="Garden.info.name"></Input>
        </FormItem>
        <FormItem label="网格类型">
          <Select v-model="Garden.info.grid_type" style="width:300px">
            <Option value="1">居民网格</Option>
            <Option value="2">非居民网格</Option>
          </Select>
        </FormItem>
        <FormItem label="网格坐标">
          <Row>
            <Col span="20">
              <Input style="width: 180px" disabled v-if="mapType === 'HT'" v-model="Garden.info.csc_mapjson_ht"></Input>
              <Input style="width: 180px" disabled v-else v-model="Garden.info.csc_mapjson"></Input>
            </Col>
            <Col span="4">
              <Button style="margin-left: 5px" @click="clickGarden">选择</Button>
            </Col>
          </Row>
        </FormItem>
      </Form>
    </div>
    <div slot="footer">
      <Button type="text" size="small" @click="Garden.Modal = false">取消</Button>
      <Button type="primary" size="small" @click="createGridConfirm()">确定</Button>
    </div>
  </Modal>
  <map-polygon-for-grarden ref="mapPolygonGarden" @returnMapInfoForGarden="returnMapInfoForGarden"></map-polygon-for-grarden>
<!--  楼-->
  <Modal
      v-model="building.Modal"
      :title="building.title"
      @on-ok="createGridConfirm">
    <div style="width: 80%">
      <Form :model="building.info" :label-width="100">
        <FormItem label="楼名称">
          <Input style="width: 300px" v-model="building.info.name"></Input>
        </FormItem>
        <FormItem label="蓝牌号">
          <Input style="width: 300px" v-model="building.info.brand"></Input>
        </FormItem>
        <FormItem label="楼坐标">
          <Row>
            <Col span="20">
              <Input v-if="mapType === 'GD'" style="width: 180px" disabled v-model="building.info.csc_mapjson"></Input>
              <Input v-if="mapType === 'HT'" style="width: 180px" disabled v-model="building.info.csc_mapjson_ht"></Input>
            </Col>
            <Col span="4">
              <Button style="margin-left: 5px" @click="clickBuilding">选择</Button>
            </Col>
          </Row>
        </FormItem>
      </Form>
    </div>
  </Modal>
  <HTMapMarkerForBuilding ref="HTmapMarkerBuilding" @HTreturnMapInfoForBuilding="HtreturnMapInfoForBuilding"></HTMapMarkerForBuilding>
  <map-marker-for-building ref="mapMarkerBuilding" @returnMapInfoForBuilding="returnMapInfoForBuilding"></map-marker-for-building>
<!--  单元-->
  <Modal
      v-model="unit.Modal"
      :title="unit.title"
      @on-ok="createGridConfirm">
    <div>
      <Form :model="unit.info" :label-width="100">
        <FormItem label="单元名称">
          <Input style="width: 300px" v-model="unit.info.name"></Input>
        </FormItem>
      </Form>
    </div>
  </Modal>
<!--  删除-->
  <Modal
      v-model="deleteGridLevel.Modal"
      :title="deleteGridLevel.title"
      @on-ok="deleteGridConfirm">
    <br>
    <h1>请确认操作,该操作会删除所创建的网格信息及其下级信息！删除数据无法恢复,请谨慎操作！</h1>
    <Form :label-width="80" :rules="ruleValidate">
      <FormItem label="删除原因" prop="desc">
        <Input v-model="note" type="textarea" :rows="4" placeholder="请填写删除原因" />
      </FormItem>
    </Form>
  </Modal>
  <Modal
      v-model="QHCodeObject.Modal"
      title="保存编码"
      @on-ok="QHCodeConfirm">
      <Input v-model="last_qh_code" style="width: 200px;margin-left: 25%;margin-bottom: 10px">
        <span slot="prepend">{{community_qh_code}} --- {{severUserInfo.level === '40' ? 1 : 2}} ---</span>
      </Input>
    <div style="color: red">注：{{community_qh_code}} 表示社区编码</div>
    <div style="color: red">注：1 表示社区，2 表示村</div>
    <div style="color: red">注：输入框部分为需要编写的
      <span v-show="QHCodeObject.info.grade === '5.5'">小区</span>
      <span v-show="QHCodeObject.info.grade === '6'">网格</span>
      编码
    </div>
    <div style="color: red">注：编码规则（编码为两位数，同社区
      <span v-show="QHCodeObject.info.grade === '5.5'">小区</span>
      <span v-show="QHCodeObject.info.grade === '6'">网格</span>
      编码编写部分不可重复，不可添加空格，特殊字符，字母，否则无法保存）</div>
    <div style="color: red">注：编写部分示例：01</div>
  </Modal>
  <Modal
      v-model="GardenQHCodeObject.Modal"
      title="保存编码"
      @on-ok="GardenQHCodeConfirm">
    <Input v-model="last_garden_qh_code" style="width: 200px;margin-left: 25%;margin-bottom: 10px">
      <span slot="prepend">{{this.residential_qh_code}} ---</span>
    </Input>
    <div style="color: red">注：{{residential_qh_code}} 表示小区编码</div>
    <div style="color: red">注：输入框部分为需要编写的
      <span v-show="QHCodeObject.info.grade === '5.5'">小区</span>
      <span v-show="QHCodeObject.info.grade === '6'">网格</span>
      编码
    </div>
    <div style="color: red">注：编码规则（编码为两位数，同社区
      <span v-show="QHCodeObject.info.grade === '5.5'">小区</span>
      <span v-show="QHCodeObject.info.grade === '6'">网格</span>
      编码编写部分不可重复，不可添加空格，特殊字符，字母，否则无法保存）</div>
    <div style="color: red">注：编写部分示例：01</div>
  </Modal>
</div>
</template>

<script>
import {
  createGridLevel,
  getCommunityAreaCode, getCommunityResidentialCode,
  newFindGridChildrenList, updateQHCodeForGarden,
  updateQHCodeForResidential
} from '../../../../api/z-new-grid'
import MapPolygonForResidential from '../map-polygon-for-residential'
import { deleteGridInfo } from '../../../../api/eventlist'
import MapPolygonForGrarden from '../map-polygon-for-garden'
import MapMarkerForBuilding from '../map-marker-for-building'
import DoorplateLevelInfo from '../doorplate-level-info'
import HTMapMarkerForBuilding from '../HT-marker-for-building'
import { mapTypeChange } from '../../../../libs/mapTypeUtil'

export default {
  name: 'gridLevelInfo',
  components: { HTMapMarkerForBuilding, DoorplateLevelInfo, MapMarkerForBuilding, MapPolygonForGrarden, MapPolygonForResidential },
  props: {
    choiceInfo: {
      type: Object
    },
    companyInfo: {
      type: Object
    }
  },
  data () {
    return {
      residential_qh_code: '',
      severUserInfo: {},
      last_qh_code: '',
      last_garden_qh_code: '',
      community_qh_code: '',
      QHCodeObject: {
        Modal: false,
        info: {}
      },
      GardenQHCodeObject: {
        Modal: false
      },
      mapType: '',
      communityList: [],
      columns: [
        {
          title: '名称',
          key: 'name',
          align: 'center'
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center'
        }
      ],
      data: [],
      floorData: [],
      createGridLevel: {
        info: {},
        title: '',
        Modal: false
      },
      updateGridLevel: {
        info: {},
        title: '',
        Modal: false
      },
      deleteGridLevel: {
        info: {},
        title: '',
        Modal: false
      },
      polygonResult: {},
      Garden: {
        info: {},
        title: '',
        Modal: false,
        type: ''
      },
      building: {
        info: {},
        title: '',
        Modal: false,
        type: ''
      },
      unit: {
        info: {},
        title: '',
        Modal: false
      },
      note: '',
      ruleValidate: {
        desc: [
          { required: true, message: '删除原因不可为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    createQHCode (e) {
      console.log(e)
      this.QHCodeObject.info = e
      if (e.grade === '5.5') {
        this.getCommunityAreaCode()
      }
      if (e.grade === '6') {
        this.getCommunityResidentialCode()
      }
    },
    getCommunityResidentialCode () {
      let data = {
        residential_id: this.QHCodeObject.info.residential_id
      }
      getCommunityResidentialCode(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.residential_qh_code = ret.data.data.qh_code
          if (this.QHCodeObject.info.qh_code !== undefined) {
            this.last_garden_qh_code = this.QHCodeObject.info.qh_code.substring(this.QHCodeObject.info.qh_code.length - 2)
          } else {
            this.last_garden_qh_code = ''
          }
          this.GardenQHCodeObject.Modal = true
        } else {
          this.$Notice.error({ title: '查询失败', desc: ret.data.errmsg })
        }
      })
    },
    getCommunityAreaCode () {
      getCommunityAreaCode().then(ret => {
        if (ret.data.errcode === 0) {
          this.community_qh_code = ret.data.data.area_code
          if (this.QHCodeObject.info.qh_code !== undefined) {
            this.last_qh_code = this.QHCodeObject.info.qh_code.substring(this.QHCodeObject.info.qh_code.length - 2)
          } else {
            this.last_qh_code = ''
          }
          this.QHCodeObject.Modal = true
        } else {
          this.$Notice.error({ title: '查询失败', desc: ret.data.errmsg })
        }
      })
    },
    QHCodeConfirm () {
      if (this.last_qh_code === '') {
        this.$Notice.error({ title: '保存失败！', desc: '1.编码不能为空' })
      }
      if (this.last_qh_code.length !== 2) {
        this.$Notice.error({ title: '保存失败！', desc: '2.编码数据格式错误' })
      }
      let data = {
        id: this.QHCodeObject.info.id,
        community_qh_code: this.community_qh_code,
        last_qh_code: this.last_qh_code,
        old_qh_code: this.QHCodeObject.info.qh_code
      }
      updateQHCodeForResidential(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Notice.success({ title: '保存成功', desc: ret.data.errmsg })
          this.community_qh_code = ''
          this.last_qh_code = ''
          this.findGridLevelList()
        } else {
          this.$Notice.error({ title: '保存失败', desc: ret.data.errmsg })
        }
      })
    },
    GardenQHCodeConfirm () {
      if (this.last_garden_qh_code === '') {
        this.$Notice.error({ title: '保存失败！', desc: '1.编码不能为空' })
      }
      if (this.last_garden_qh_code.length !== 2) {
        this.$Notice.error({ title: '保存失败！', desc: '2.编码数据格式错误' })
      }
      let data = {
        id: this.QHCodeObject.info.id,
        residential_qh_code: this.residential_qh_code,
        last_garden_qh_code: this.last_garden_qh_code
      }
      updateQHCodeForGarden(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Notice.success({ title: '保存成功', desc: ret.data.errmsg })
          this.residential_qh_code = ''
          this.last_garden_qh_code = ''
          this.findGridLevelList()
        } else {
          this.$Notice.error({ title: '保存失败', desc: ret.data.errmsg })
        }
      })
    },
    findGridLevelList () {
      let data = {
        grade: this.choiceInfo.grade,
        id: this.choiceInfo.id
      }
      newFindGridChildrenList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.communityList = ret.data.data
          if (this.choiceInfo.grade === '8') {
            this.floorData = ret.data.data
          } else {
            this.data = ret.data.data
          }
          if (this.choiceInfo.grade === '5.5' || this.choiceInfo.grade === '5') {
            this.columns = [
              {
                title: '名称',
                key: 'name',
                align: 'center'
              },
              {
                title: '编码',
                key: 'qh_code',
                align: 'center'
              },
              {
                title: '操作',
                slot: 'action',
                align: 'center'
              }
            ]
          }
        } else {
          this.$Notice.error({ title: '查询失败', desc: ret.data.errmsg })
        }
      })
    },
    updateGrid (e) {
      console.log('eeee', e)
      if (this.choiceInfo.grade === '2' || this.choiceInfo.grade === '3' || this.choiceInfo.grade === '4') {
        this.$Notice.error({ title: '当前层级不允许此操作！' })
        return
      }
      if (this.choiceInfo.grade === '5') {
        this.updateGridLevel.title = '修改小区信息'
        this.updateGridLevel.info = e
        this.updateGridLevel.Modal = true
      }
      if (this.choiceInfo.grade === '5.5') {
        this.Garden.title = '修改网格信息'
        this.Garden.info = e
        this.Garden.Modal = true
        this.Garden.type = 'update'
      }
      if (this.choiceInfo.grade === '6') {
        this.building.title = '修改楼信息'
        this.building.info = e
        this.building.Modal = true
        this.building.type = 'update'
      }
      if (this.choiceInfo.grade === '7') {
        this.unit.title = '修改单元信息'
        this.unit.info = e
        this.unit.Modal = true
      }
    },
    deleteGrid (e) {
      if (this.choiceInfo.grade === '2' || this.choiceInfo.grade === '3' || this.choiceInfo.grade === '4') {
        this.$Notice.error({ title: '当前帐号不允许此操作！' })
        return
      }
      this.deleteGridLevel.info = e
      this.deleteGridLevel.Modal = true
    },
    deleteGridConfirm () {
      let data = {
        grade: this.deleteGridLevel.info.grade,
        id: this.deleteGridLevel.info.id,
        note: this.note
      }
      if (data.note === '' || data.note === null || data.note === undefined) {
        this.$Notice.error({ title: '删除用户网格信息失败，删除原因不能为空', desc: '' })
      } else {
        deleteGridInfo(data).then(ret => {
          if (ret.data.errcode === 0) {
            this.$Notice.success({ title: '删除成功！', desc: ret.data.errmsg })
            this.findGridLevelList()
            this.note = ''
          } else {
            this.$Notice.error({ title: '删除失败！', desc: ret.data.errmsg })
          }
        })
      }
    },
    createGrid () {
      if (this.choiceInfo.grade === '2' || this.choiceInfo.grade === '3' || this.choiceInfo.grade === '4') {
        this.$Notice.error({ title: '当前层级不允许此操作！' })
        return
      }
      if (this.choiceInfo.grade === '5') {
        this.createGridLevel.title = '创建小区'
        this.createGridLevel.info = {}
        this.createGridLevel.Modal = true
      }
      if (this.choiceInfo.grade === '5.5') {
        this.Garden.title = '创建网格'
        this.Garden.info = {}
        this.Garden.Modal = true
        this.Garden.type = 'create'
      }
      if (this.choiceInfo.grade === '6') {
        this.building.title = '创建楼'
        this.building.info = {}
        this.building.Modal = true
        this.building.type = 'create'
      }
      if (this.choiceInfo.grade === '7') {
        this.unit.title = '创建单元'
        this.unit.info = {}
        this.unit.Modal = true
      }
    },
    createGridConfirm (e) {
      console.log('提交')
      let data = {}
      if (this.choiceInfo.grade === '5') {
        if (Object.keys(this.polygonResult).length !== 0) {
          if (!this.polygonResult.result) {
            this.$Notice.error({ title: '数据异常！', desc: this.polygonResult.name + '与当前小区范围重合-2' })
            return
          }
        }
        if (e === 'create') {
          data = this.createGridLevel.info
          data.grade = '5.5'
        }
        if (e === 'update') {
          data = this.updateGridLevel.info
          data.grade = '5.5'
        }
      }
      if (this.choiceInfo.grade === '5.5') {
        if (Object.keys(this.polygonResult).length !== 0) {
          if (!this.polygonResult.result) {
            this.$Notice.error({ title: '数据异常！', desc: this.polygonResult.name + '与当前网格范围重合-2' })
            return
          }
        }
        data = this.Garden.info
        data.grade = '6'
        data.residential_id = this.choiceInfo.id
      }
      if (this.choiceInfo.grade === '6') {
        if (this.mapType === 'GD') {
          if (!(this.building.info.markerResult)) {
            this.$Notice.error({ title: '数据异常！', desc: '楼坐标点位不在网格范围内！' })
            return
          }
        }
        if (this.mapType === 'HT') {
          if (this.building.info.csc_mapjson_ht === 'undefined,undefined') {
            this.$Notice.error({ title: '数据异常！', desc: '请选择楼位置！' })
            return
          }
        }
        data = this.building.info
        data.grade = '7'
        data.garden_id = this.choiceInfo.id
        data.mapType = this.mapType
      }
      if (this.choiceInfo.grade === '7') {
        data = this.unit.info
        data.grade = '8'
        data.building_id = this.choiceInfo.id
      }
      console.log(data)
      if (!data.mapType) {
        data.mapType = this.$route.query.mapType || mapTypeChange()
      }
      createGridLevel(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.createGridLevel.info = {}
          this.$Notice.success({ title: '创建成功！', desc: ret.data.errmsg })
          this.Garden.Modal = false
          this.findGridLevelList()
        } else {
          this.$Notice.error({ title: '创建失败！', desc: ret.data.errmsg })
        }
      })
    },
    clickResidential () {
      this.$refs.mapPolygonResidential.init(this.choiceInfo, this.communityList, this.companyInfo.csc_mapjson_ht)
    },
    clickResidentialForUpdate () {
      this.$refs.mapPolygonResidential.updateInit(this.updateGridLevel.info, this.communityList, this.companyInfo.csc_mapjson_ht)
    },
    returnMapInfoForResidential (e) {
      console.log(e, '提交的数据')
      this.polygonResult = {}
      if (Object.keys(e.polygonResult).length !== 0) {
        this.polygonResult = e.polygonResult
        this.polygonResult.result = false
      }
      if (e.operationType === 'create') {
        this.createGridLevel.Modal = false
        this.$nextTick(() => {
          this.createGridLevel.Modal = true
        })
        if (e.name) {
          this.createGridLevel.info.name = e.name
        }
        if (e.address) {
          this.createGridLevel.info.address = e.address
        }
        if (e.csc_mapjson) {
          this.createGridLevel.info.csc_mapjson = e.csc_mapjson
        }
        if (e.csc_mapjson_ht) {
          this.createGridLevel.info.csc_mapjson_ht = e.csc_mapjson_ht
        }
        if (e.mapType) {
          this.createGridLevel.info.mapType = e.mapType
        } else {
          this.createGridLevel.info.mapType = this.$route.query.mapType || mapTypeChange()
        }
        if (e.measure) {
          this.createGridLevel.info.measure = e.measure.toFixed(2)
        }
      }
      if (e.operationType === 'update') {
        this.updateGridLevel.Modal = false
        this.$nextTick(() => {
          this.updateGridLevel.Modal = true
        })
        if (e.name) {
          this.updateGridLevel.info.name = e.name
        }
        if (e.address) {
          this.updateGridLevel.info.address = e.address
        }
        if (e.csc_mapjson) {
          this.updateGridLevel.info.csc_mapjson = e.csc_mapjson
        }
        if (e.csc_mapjson_ht) {
          this.updateGridLevel.info.csc_mapjson_ht = e.csc_mapjson_ht
        }
        if (e.mapType) {
          this.updateGridLevel.info.mapType = e.mapType
        } else {
          this.updateGridLevel.info.mapType = this.$route.query.mapType || mapTypeChange()
        }
        if (e.measure) {
          this.updateGridLevel.info.measure = e.measure.toFixed(2)
        }
      }
    },
    clickGarden () {
      if (this.Garden.type === 'create') {
        this.$refs.mapPolygonGarden.init(this.choiceInfo)
      }
      if (this.Garden.type === 'update') {
        this.$refs.mapPolygonGarden.updateInit(this.Garden.info, this.choiceInfo)
      }
    },
    returnMapInfoForGarden (e) {
      console.log(e)
      this.polygonResult = {}
      if (Object.keys(e.polygonResult).length !== 0) {
        this.polygonResult = e.polygonResult
        this.polygonResult.result = false
      }
      this.Garden.info.csc_mapjson = e.csc_mapjson
      this.Garden.info.csc_mapjson_ht = e.csc_mapjson_ht

      if (e.mapType) {
        this.Garden.info.mapType = e.mapType
      } else {
        this.Garden.info.mapType = this.$route.query.mapType || mapTypeChange()
      }
      this.Garden.Modal = false
      this.$nextTick(() => {
        this.Garden.Modal = true
      })
    },
    clickBuilding () {
      if (this.mapType === 'GD') {
        if (this.building.type === 'create') {
          this.$refs.mapMarkerBuilding.init(this.choiceInfo)
        }
        if (this.building.type === 'update') {
          this.$refs.mapMarkerBuilding.updateInitMap(this.building.info, this.choiceInfo)
        }
      }
      if (this.mapType === 'HT') {
        if (this.building.type === 'create') {
          this.$refs.HTmapMarkerBuilding.init(this.choiceInfo)
        }
        if (this.building.type === 'update') {
          this.$refs.HTmapMarkerBuilding.updateInitMap(this.building.info, this.choiceInfo)
        }
      }
    },
    returnMapInfoForBuilding (e) {
      this.building.info.csc_mapjson = e.csc_mapjson.lng + ',' + e.csc_mapjson.lat
      this.building.info.markerResult = e.markerResult
      this.building.Modal = false
      this.$nextTick(() => {
        this.building.Modal = true
      })
    },
    HtreturnMapInfoForBuilding (e) {
      this.building.info.csc_mapjson_ht = e.csc_mapjson_ht
      this.building.Modal = false
      this.$nextTick(() => {
        this.building.Modal = true
      })
    },
    reloadData () {
      this.findGridLevelList()
    }
  },
  watch: {
    'choiceInfo.id': function (newV, oldV) {
      if (newV !== oldV) {
        try {
          this.findGridLevelList()
        } catch (e) {
          // console.log('choiceInfo.id', e)
        }
      }
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
    if (this.$route.query.mapType === 'HT') {
      this.mapType = 'HT'
    } else {
      this.mapType = mapTypeChange()
    }
    if (Object.keys(this.choiceInfo).length !== 0) {
      this.findGridLevelList()
    }
  }
}
</script>

<style scoped>

</style>
